home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / enemy / BatA.as next >
Encoding:
Text File  |  2011-10-17  |  16.4 KB  |  563 lines

  1. class classes.enemy.BatA
  2. {
  3.    var x;
  4.    var y;
  5.    var moveScript;
  6.    var matrixCoords;
  7.    var form;
  8.    var id;
  9.    var clip;
  10.    var colorR;
  11.    var trans;
  12.    var colorTrans;
  13.    var advanceMax;
  14.    var advanceMax2;
  15.    var matrixVar;
  16.    var dir;
  17.    var f2;
  18.    var axis;
  19.    var xDest;
  20.    var yDest;
  21.    var oldDir;
  22.    var xMov = 0;
  23.    var yMov = 0;
  24.    var xmt = 0;
  25.    var ymt = 0;
  26.    var xMovT = 0;
  27.    var yMovT = 0;
  28.    var speedOrig = 8;
  29.    var speed = 8;
  30.    var xDestMet = false;
  31.    var yDestMet = false;
  32.    var c = 0;
  33.    var feelerInfo = [[-400,0,400,40],[0,0,400,40],[0,-400,40,400],[0,0,40,400]];
  34.    var dirArray = ["L","R","U","D"];
  35.    var power = 25;
  36.    var life = 1;
  37.    var nudging = false;
  38.    var nc = 0;
  39.    var xA = 0;
  40.    var yA = 0;
  41.    var Name = "batA";
  42.    function BatA(px, py, pmoveScript, pmatrixCoords, pform, pid)
  43.    {
  44.       this.x = px;
  45.       this.y = py;
  46.       this.moveScript = pmoveScript.slice();
  47.       this.matrixCoords = pmatrixCoords.slice();
  48.       this.form = pform.slice();
  49.       this.id = pid;
  50.       _root.d = _root.d + 1;
  51.       this.clip = _root.attachMovie("batA","batA" + this.id + "Clip",_root.d + 50000);
  52.       this.clip._x = this.x;
  53.       this.clip._y = this.y;
  54.       this.colorR = _root.randRange(-10,20);
  55.       this.trans = new flash.geom.Transform(this.clip);
  56.       this.colorTrans = new flash.geom.ColorTransform(1,1,1,1,this.colorR,this.colorR,this.colorR,0);
  57.       this.trans.colorTransform = this.colorTrans;
  58.       this.speed *= _root.dif.speed;
  59.       this.speedOrig = this.speed;
  60.       this.advanceMax = 60 / (this.speed / 2);
  61.       this.advanceMax2 = 50 / (this.speed / 2);
  62.       if(this.matrixCoords[0] == "free")
  63.       {
  64.          this.matrixVar = 0;
  65.       }
  66.       else
  67.       {
  68.          this.matrixVar = 1;
  69.       }
  70.       this.speedVar();
  71.       this.parseMoveScript();
  72.       _root.stats.created = _root.stats.created + 1;
  73.    }
  74.    function broBehind()
  75.    {
  76.       this.matrixVar = 0;
  77.       this.yMovT = 0;
  78.       if(random(3) == 1)
  79.       {
  80.          var _loc3_ = _root.randRange2(1,1.1);
  81.          this.xMovT = this.dir != "L" ? _loc3_ * this.speed : -1 * _loc3_ * this.speed;
  82.          this.clip.body.gotoAndPlay("spread");
  83.          this.f2 = "attacking";
  84.       }
  85.       else
  86.       {
  87.          this[this.axis + "MovT"] = 0;
  88.          this.axis = random(2) <= 0 ? "x" : "y";
  89.          _loc3_ = _root.randRange2(0.9,1.1);
  90.          this[this.axis + "MovT"] = random(2) <= 0 ? -1 * _loc3_ * this.speed : _loc3_ * this.speed;
  91.          this.getDirString();
  92.          this.f2 = "wander";
  93.       }
  94.    }
  95.    function nudge(pxA, pyA, pscale)
  96.    {
  97.       this.nc = 0;
  98.       this.nudging = true;
  99.       var _loc2_ = pscale / 100;
  100.       this.xA = pxA * _loc2_;
  101.       this.yA = pyA * _loc2_;
  102.    }
  103.    function speedVar()
  104.    {
  105.       if(random(3) == 1)
  106.       {
  107.          this.speed *= _root.randRange2(0.9999,1.0001);
  108.       }
  109.    }
  110.    function bombed(num)
  111.    {
  112.       this.f2 = "death";
  113.    }
  114.    function twist()
  115.    {
  116.       this.clip.body.gotoAndPlay("twist");
  117.    }
  118.    function parseMoveScript()
  119.    {
  120.       this.dir = this.moveScript[0];
  121.       if(this.dir == "break")
  122.       {
  123.          delete this.moveScript;
  124.          this[this.axis + "MovT"] = 0;
  125.          if(this.matrixCoords[0] == "free")
  126.          {
  127.             this.f2 = "wander";
  128.             this.axis = random(10) <= 4 ? "y" : "x";
  129.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  130.             this.speedVar();
  131.             this.getDirString();
  132.          }
  133.          else
  134.          {
  135.             this.xDest = _root.advanceDir != "L" ? this.matrixCoords[0] * 60 : this.matrixCoords[0] * 60 + 320;
  136.             this.yDest = this.matrixCoords[1] * 50 + 10;
  137.             this.axis = Math.abs(this.xDest - this.x) <= Math.abs(this.yDest - this.y) ? "y" : "x";
  138.             this[this.axis + "MovT"] = this[this.axis + "Dest"] <= this[this.axis] ? -1 * this.speed : this.speed;
  139.             this.getDirString();
  140.             this.speedVar();
  141.             this.f2 = "gotoMatrix";
  142.          }
  143.       }
  144.       else
  145.       {
  146.          this[this.axis + "MovT"] = 0;
  147.          this.f2 = "gotoXYDest";
  148.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  149.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  150.          this.speedVar();
  151.          if(this.dir == "L" || this.dir == "U")
  152.          {
  153.             this[this.axis + "Dest"] = this[this.axis] - this.moveScript[1];
  154.          }
  155.          else
  156.          {
  157.             this[this.axis + "Dest"] = this[this.axis] + this.moveScript[1];
  158.          }
  159.          this.moveScript.splice(0,2);
  160.       }
  161.    }
  162.    function gotoXYDest()
  163.    {
  164.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  165.       {
  166.          if(this.axis == "x")
  167.          {
  168.             this.x = this.xDest;
  169.          }
  170.          else
  171.          {
  172.             this.y = this.yDest;
  173.          }
  174.          this.parseMoveScript();
  175.       }
  176.    }
  177.    function gotoMatrix()
  178.    {
  179.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  180.       {
  181.          if(this.axis == "x")
  182.          {
  183.             this.x = this.xDest;
  184.          }
  185.          else
  186.          {
  187.             this.y = this.yDest;
  188.          }
  189.          this[this.axis + "MovT"] = 0;
  190.          this.axis = this.axis != "x" ? "x" : "y";
  191.          this[this.axis + "MovT"] = this[this.axis + "Dest"] <= this[this.axis] ? -1 * this.speed : this.speed;
  192.          this.getDirString();
  193.          this.speed = this.speedOrig;
  194.       }
  195.       if(Math.abs(this.x - this.xDest) < this.speed + 1 && Math.abs(this.y - this.yDest) < this.speed + 1)
  196.       {
  197.          this.x = this.clip._x = this.xDest;
  198.          this.y = this.clip._y = this.yDest;
  199.          this.xMovT = this.xMov = 0;
  200.          this.yMovT = this.yMov = 0;
  201.          this.matrixVar = 2;
  202.          this.dir = _root.advanceDir;
  203.          _root.matrixNum = _root.matrixNum + 1;
  204.          if(_root.matrixNum >= _root.matrixSize)
  205.          {
  206.             _root.matrixComplete = true;
  207.          }
  208.          _root["formB" + this.form[0]] = "matrixed";
  209.          this.f2 = "wait";
  210.       }
  211.    }
  212.    function getDirString()
  213.    {
  214.       if(this.xMovT < -1)
  215.       {
  216.          this.dir = "L";
  217.       }
  218.       else if(this.xMovT > 1)
  219.       {
  220.          this.dir = "R";
  221.       }
  222.       else if(this.yMovT > 1)
  223.       {
  224.          this.dir = "D";
  225.       }
  226.       else if(this.yMovT < -1)
  227.       {
  228.          this.dir = "U";
  229.       }
  230.    }
  231.    function wait()
  232.    {
  233.       if(random(1000) >= 998 + _root.dif.wait && _root.matrixComplete)
  234.       {
  235.          this.dir = this.findDir();
  236.          if(this.dir == _root.advanceDir)
  237.          {
  238.             this.clip.body.gotoAndPlay("spread");
  239.             this.xMovT = _root.advanceDir != "L" ? this.speed : -1 * this.speed;
  240.             this.f2 = "attacking";
  241.             this.matrixVar = 0;
  242.          }
  243.          else if(this.dir == "U" || this.dir == "D")
  244.          {
  245.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  246.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  247.             this.matrixVar = 0;
  248.             this.c = 0;
  249.             this.f2 = "leavingMatrix";
  250.          }
  251.       }
  252.    }
  253.    function evade()
  254.    {
  255.       if(this.matrixVar == 2)
  256.       {
  257.          this.matrixVar = 0;
  258.          if(random(2) == 1)
  259.          {
  260.             this.f2 = "wander";
  261.             this[this.axis + "MovT"] = 0;
  262.             this.axis = random(10) <= 4 ? "y" : "x";
  263.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  264.             this.speedVar();
  265.             this.getDirString();
  266.          }
  267.          else
  268.          {
  269.             this.clip.body.gotoAndPlay("spread");
  270.             this.xMovT = _root.advanceDir != "L" ? this.speed : -1 * this.speed;
  271.             this.f2 = "attacking";
  272.          }
  273.       }
  274.    }
  275.    function leavingMatrix()
  276.    {
  277.       this.c = this.c + 1;
  278.       if(this.c > this.advanceMax2)
  279.       {
  280.          this.c = 0;
  281.          this.dir = this.findDir();
  282.          if(this.dir == _root.advanceDir)
  283.          {
  284.             this.clip.body.gotoAndPlay("spread");
  285.             this.yMovT = 0;
  286.             this.xMovT = _root.advanceDir != "L" ? this.speed : -1 * this.speed;
  287.             this.f2 = "attacking";
  288.          }
  289.       }
  290.    }
  291.    function findDir()
  292.    {
  293.       _root.d = _root.d + 1;
  294.       _root.attachMovie("feeler","feelerClip",_root.d);
  295.       var _loc7_ = [];
  296.       var _loc9_ = 0;
  297.       var _loc11_ = this.dirArray.length;
  298.       while(_loc9_ < _loc11_)
  299.       {
  300.          _root.feelerClip._x = this.x + this.feelerInfo[_loc9_][0];
  301.          _root.feelerClip._y = this.y + this.feelerInfo[_loc9_][1];
  302.          _root.feelerClip._width = this.feelerInfo[_loc9_][2];
  303.          _root.feelerClip._height = this.feelerInfo[_loc9_][3];
  304.          var _loc3_ = 0;
  305.          var _loc8_ = _root.chars.length;
  306.          var _loc6_ = false;
  307.          while(_loc3_ < _loc8_)
  308.          {
  309.             var _loc5_ = _root.chars[_loc3_] + "Clip";
  310.             if(_root.feelerClip.hitTest(_root[_loc5_]))
  311.             {
  312.                var _loc4_ = _root.chars[_loc3_];
  313.                if(_root[_loc4_].matrixVar == 2 && _loc4_ != this.Name + this.id)
  314.                {
  315.                   _loc6_ = true;
  316.                   break;
  317.                }
  318.             }
  319.             _loc3_ = _loc3_ + 1;
  320.          }
  321.          if(!_loc6_)
  322.          {
  323.             var _loc10_ = _root.advanceDir != "L" ? "L" : "R";
  324.             if(this.dirArray[_loc9_] != _loc10_)
  325.             {
  326.                _loc7_.push(this.dirArray[_loc9_]);
  327.             }
  328.          }
  329.          _loc9_ = _loc9_ + 1;
  330.       }
  331.       _loc9_ = 0;
  332.       _loc11_ = _loc7_.length;
  333.       if(_loc9_ < _loc11_)
  334.       {
  335.          if(_loc7_[_loc9_] == _root.advanceDir)
  336.          {
  337.             return _root.advanceDir;
  338.          }
  339.          return _loc7_[random(_loc7_.length)];
  340.       }
  341.    }
  342.    function attacking()
  343.    {
  344.       this.xMovT *= 1.03;
  345.       this.yMovT *= 1.03;
  346.    }
  347.    function death()
  348.    {
  349.       _root.stats.destroyed = _root.stats.destroyed + 1;
  350.       _root.stats.score += 250;
  351.       if(this.matrixVar == 1)
  352.       {
  353.          _root.matrixNum = _root.matrixNum + 1;
  354.          if(_root.matrixNum >= _root.matrixSize)
  355.          {
  356.             _root.matrixComplete = true;
  357.          }
  358.       }
  359.       _root.powerUp(this.x,this.y,96);
  360.       var _loc3_ = 0;
  361.       var _loc4_ = _root["form" + this.form[0]].length;
  362.       while(_loc3_ < _loc4_)
  363.       {
  364.          if(_root["form" + this.form[0]][_loc3_] == "batA" + this.id)
  365.          {
  366.             _root["form" + this.form[0]].splice(_loc3_,1);
  367.             if(_root["form" + this.form[0]].length == 0)
  368.             {
  369.                delete _root["form" + this.form[0]];
  370.                if(_root["formB" + this.form[0]] == "matrixed")
  371.                {
  372.                   _loc3_ = 0;
  373.                   _loc4_ = random(2) + 1;
  374.                   while(_loc3_ < _loc4_)
  375.                   {
  376.                      _root.createPowerUp([this.x,this.y,"coin1"]);
  377.                      _loc3_ = _loc3_ + 1;
  378.                   }
  379.                   _root.stats.score += 250;
  380.                }
  381.                else
  382.                {
  383.                   _loc3_ = 0;
  384.                   _loc4_ = random(3) + 1;
  385.                   while(_loc3_ < _loc4_)
  386.                   {
  387.                      _root.createPowerUp([this.x,this.y,"coin1"]);
  388.                      _loc3_ = _loc3_ + 1;
  389.                   }
  390.                   _root.stats.score += 500;
  391.                }
  392.                delete _root["formB" + this.form[0]];
  393.             }
  394.             break;
  395.          }
  396.          _loc3_ = _loc3_ + 1;
  397.       }
  398.       _root.createExploA([this.x + this.clip._width / 2,this.y + this.clip._height / 2,_root.randRange(80,130),_root.randRange(75,100),"Yellow"]);
  399.       _root.audio.playLevel4("batX" + (random(2) + 1),_root.randRange(8,15));
  400.       var _loc5_ = 0;
  401.       var _loc6_ = random(3);
  402.       while(_loc5_ < _loc6_)
  403.       {
  404.          _root.createShrapnel([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"batA","Yellow"]);
  405.          _loc5_ = _loc5_ + 1;
  406.       }
  407.       _root.createEnemySoul([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"yellow"]);
  408.       _root.removeChar("batA" + this.id);
  409.       this.f2 = "";
  410.    }
  411.    function advance()
  412.    {
  413.       this.dir = _root.advanceDir;
  414.       this.clip.body.gotoAndPlay("advance");
  415.       this.xMovT = _root.advanceDir != "L" ? 1 * (this.speed / 2) : -1 * (this.speed / 2);
  416.       this.f2 = "advancing";
  417.    }
  418.    function advancing()
  419.    {
  420.       this.c = this.c + 1;
  421.       if(this.c > this.advanceMax)
  422.       {
  423.          this.xMovT = 0;
  424.          this.c = 0;
  425.          this.f2 = "wait";
  426.          _root.d = _root.d + 1;
  427.          _root.attachMovie("sight","sightClip",_root.d);
  428.          _root.sightClip.gotoAndStop("hindSight");
  429.          _root.sightClip._x = this.x;
  430.          _root.sightClip._y = this.y;
  431.          if(_root.advanceDir == "L")
  432.          {
  433.             _root.sightClip._rotation = 180;
  434.          }
  435.          if(_root.sightClip.hitTest(_root[_root.char].x,_root[_root.char].y,true))
  436.          {
  437.             _root.broBehind();
  438.          }
  439.          removeMovieClip(_root.sightClip);
  440.       }
  441.    }
  442.    function wander()
  443.    {
  444.       if(random(100) > 98 + _root.dif.wander)
  445.       {
  446.          this[this.axis + "MovT"] = 0;
  447.          this.axis = this.axis != "x" ? "x" : "y";
  448.          this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  449.          this.getDirString();
  450.       }
  451.    }
  452.    function death2()
  453.    {
  454.       _root.removeChar("batA" + this.id);
  455.       this.f2 = "";
  456.    }
  457.    function main()
  458.    {
  459.       this[this.f2]();
  460.       if(this.oldDir != this.dir)
  461.       {
  462.          this.clip.gotoAndStop("fly" + this.dir);
  463.       }
  464.       this.oldDir = this.dir;
  465.       if(this.nudging)
  466.       {
  467.          this.xA *= 0.5;
  468.          this.yA *= 0.5;
  469.          this.nc = this.nc + 1;
  470.          var _loc8_ = 255 - this.nc * 17;
  471.          this.colorTrans.redOffset = _loc8_;
  472.          this.colorTrans.blueOffset = _loc8_;
  473.          this.trans.colorTransform = this.colorTrans;
  474.          if(this.nc == 15)
  475.          {
  476.             this.xA = this.yA = 0;
  477.             this.nudging = false;
  478.             this.colorTrans.redOffset = this.colorR;
  479.             this.colorTrans.blueOffset = this.colorR;
  480.             this.trans.colorTransform = this.colorTrans;
  481.          }
  482.       }
  483.       var _loc4_ = 0;
  484.       var _loc7_ = _root.broShots.length;
  485.       while(_loc4_ < _loc7_)
  486.       {
  487.          var _loc6_ = _root.broShots[_loc4_] + "Clip";
  488.          if(this.clip.hitTest(_root[_loc6_]))
  489.          {
  490.             var _loc3_ = _root.broShots[_loc4_];
  491.             var _loc5_ = this.life;
  492.             this.life -= _root[_loc3_].power;
  493.             if(this.life < 1)
  494.             {
  495.                this.f2 = "death";
  496.             }
  497.             else
  498.             {
  499.                this.nudge(_root[_loc3_].xMov,_root[_loc3_].yMov,10);
  500.             }
  501.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar;
  502.             _root[_loc3_].exploX = this.x + this.clip._width / 2;
  503.             _root[_loc3_].exploY = this.y + this.clip._height / 2;
  504.             _root[_loc3_].hit(_loc5_);
  505.             break;
  506.          }
  507.          _loc4_ = _loc4_ + 1;
  508.       }
  509.       if(this.clip.hitTest(_root[_root.char + "Clip"]))
  510.       {
  511.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  512.          this.f2 = "death";
  513.       }
  514.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  515.       {
  516.          delete _root["form" + this.form[0]];
  517.          delete _root["formB" + this.form[0]];
  518.          this.f2 = "death2";
  519.       }
  520.       if(this.xMovT < this.xMov)
  521.       {
  522.          this.xMov -= 1;
  523.       }
  524.       else if(this.xMovT > this.xMov)
  525.       {
  526.          this.xMov += 1;
  527.       }
  528.       else
  529.       {
  530.          this.xMov = this.xMovT;
  531.       }
  532.       if(this.yMovT < this.yMov)
  533.       {
  534.          this.yMov -= 1;
  535.       }
  536.       else if(this.yMovT > this.yMov)
  537.       {
  538.          this.yMov += 1;
  539.       }
  540.       else
  541.       {
  542.          this.yMov = this.yMovT;
  543.       }
  544.       this.xmt = this.xMov;
  545.       this.ymt = this.yMov;
  546.       if(random(10) == 1)
  547.       {
  548.          if(this.axis == "y")
  549.          {
  550.             this.xmt += _root.randRange2(-1,1);
  551.          }
  552.          else
  553.          {
  554.             this.ymt += _root.randRange2(-1,1);
  555.          }
  556.       }
  557.       this.x += this.xmt;
  558.       this.y += this.ymt;
  559.       this.clip._x = this.x;
  560.       this.clip._y = this.y;
  561.    }
  562. }
  563.